< previous page page_82 next page >

Page 82
TABLE 3.1 BANK ACCOUNT CODES.
ProductCode
Basic Personal Savings01
Basic Personal Checking02
Personal Savings Plus11
Personal Checking Plus12

As the architect, you decide you want only one creator class with a factory method for any kind of bank product. You aptly name this class AccountCreator and decide to locate it on an account application server (I Won't discuss second-tier servers here, for simplicity) to keep the client as thin as possible. (Note that thin means the client has only enough code to move information in and out of the user interface.) The product classes are BasicPersonalChecking,BasicPersonalSavings, PersonalCheckingPlus, and PersonalSavingsPlus. These products implement the BankAccountProduct interface class.
The AccountCreator interface class has the following members:
Public Function createAccount(ByRef argObject) As BankAccountProduct
Private Function createBasicPersonalChecking(argObject) As BasicPersonalChecking
Private Function createBasicPersonalSavings(argObject) As BasicPersonalSavings
Private Function createPersonalCheckingPlus(argObject) As PersonalCheckingPlus
Private Function createPersonalSavingsPlus(argObject) As PersonalSavingsPlus
Public Function getBankAccountCode()
Public Sub setBankAccountCode(argAccountCode As Byte)
The method createAccount is the factory method. A factory method creates objects of a particular class as if it were an object factory. Within it are invocations of private methods that are responsible for first making sure each one is able to create the requested bank product (known as a precondition). If so, the method creates the corresponding product by instantiating the appropriate object. The methods responsible for instantiating the proper bank product are createBasicPersonalChecking, createBasicPersonalSavings, createPersonalCheckingPlus, and createPersonalSavingsPlus. The methods getBankAccountCode and setBankAccountCode enable users of the AccountCreator object to get and set, respectively, the product code of the type of bank product the customer wants. These are also known respectively as getters and setters or, more formally, accessors and mutators. Refer to this chapter's code on the CD-ROM for more information.

 
< previous page page_82 next page >

If you like this book, buy it!